package com.syj.jsxjj.ui.my.activity;

import android.text.TextUtils;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.syj.jsxjj.R;
import com.syj.jsxjj.app.App;
import com.syj.jsxjj.base.BaseActivity;
import com.syj.jsxjj.config.Constant;
import com.syj.jsxjj.ui.lend.activity.LoanActivity;
import com.syj.jsxjj.ui.lend.fragment.ProductListFragment;
import com.syj.jsxjj.widget.loading.LoadingLayout;

import java.util.Date;
import java.util.GregorianCalendar;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by gym on 2017/2/16 0016.
 * 描述：借款记录
 */

public class TransactionRecordActivity extends BaseActivity {

    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.fl_product_list)
    FrameLayout flProductList;
    @BindView(R.id.tv_more_product)
    TextView tvMoreProduct;
    @BindView(R.id.load_view)
    LoadingLayout loadView;

    @Override
    public int getLayoutId() {
        return R.layout.activity_transaction_record;
    }

    @Override
    public void initPresenter() {

    }

    @Override
    public void loadData() {
        mTitle.setTitle("借款记录");
        //String status = SpUtil.getString(Constant.CACHE_LOAN_STATUS);
        //long time = SpUtil.getLong(Constant.CACHE_TIME);
        int countDown = (int) (30 - (System.currentTimeMillis() - App.getConfig().getUserInfo().getLoanTime()) / 1000);//间隔时间，小于30秒显示倒计时页面
        if (!TextUtils.isEmpty(App.getConfig().getUserInfo().getLoanStatus())&&App.getConfig().getUserInfo().getLoanStatus().equals(Constant.CACHE_LOANED)&&countDown < 0){
            loadView.setStatus(LoadingLayout.Success);
            Date dat=new Date(App.getConfig().getUserInfo().getLoanTime());
            GregorianCalendar gc = new GregorianCalendar();
            gc.setTime(dat);
            java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String sb=format.format(gc.getTime());
            tvTime.setText(sb);
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.fl_product_list
                            , ProductListFragment.newInstance(App .arrayList)).commit();
        }else{
            loadView.setEmptyText("暂无借款记录")
                    .setStatus(LoadingLayout.Empty);
        }
    }

    @OnClick(R.id.tv_more_product)
    public void onViewClicked() {
        startActivity(LoanActivity.class);
    }
}
